package com.yxp.hard.astar;

import java.util.ArrayList;

public class SortLinkedList extends ArrayList<AStarNode> {

    private static final long serialVersionUID = 7376325045990600917L;

    @Override
    public boolean add(AStarNode node) {
        int size = size();
        for (int i = 0; i < size; i++) {
            if (node.compareTo(get(i)) <= 0) {
                add(i, node);
                return true;
            }
        }
        addLast(node);
        return true;
    }

    public AStarNode removeFirst() {
        if (size() > 0) {
            return remove(0);
        }
        return null;
    }

    private void addLast(AStarNode node) {
        add(size(), node);
    }
}
